/*
 * Copyright (c) 2019-2029 深圳金雅福控股集团有限公司 All Rights Reserved.FileName: DataSourceConfig.java @author 000062064@date: 19-6-10 上午11:19@date 2022/4/7
 */

package com.zhang.mysql;


import com.zhang.mysql.properties.DbHikarConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * 一主多从数据源，不支持从数据源事务
 */
@Configuration
@Order(2)
public class DataHikarSourceConfig {

    @Autowired
    private DbHikarConfig dbHikarConfig;

    /**
     * 主数据源配置
     * @return
     */
   @Bean(name = "masterDataSource")
   @Primary
    public DataSource masterDataSource() throws SQLException {
       return  dbHikarConfig.getMaster();
    }

    /**
     * 读数据源
     *
     * @return
     */
    @Bean(name = "slave1DataSource")
    public DataSource slave1DataSource() {
       return dbHikarConfig.getSalve1();
    }


    @Bean(name = "slave2DataSource")

    public DataSource slave2DataSource() {
        return dbHikarConfig.getSalve2();
    }



}
